<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>IQC来料检验十差供应商</title>
    <link rel="stylesheet" href="/3nod_web/layui/css/layui.css" media="all">
</head>
<body>
<div id="content">
    <h1>IQC来料检验十差供应商</h1>
    <div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年月</label>
                <div class="layui-input-inline" style="width:130px;">
                    <input type="text" name="time" id="time" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button id="search" class="layui-btn layui-btn-sm" data-type="reload">搜索</button>
            </div>
            <div class="layui-inline">
                <a href="/3nod_web/exportSuppliedMaterialsBadTop10List">
                    <button class="layui-btn  layui-btn-sm">导出</button>
                </a>
            </div>
            <div class="layui-inline">
                <button id="save" class="layui-btn layui-btn-sm" data-type="reload">刷新</button>
            </div>
        </div>
    </div>

</div>
<table class="layui-hide" id="demo" lay-filter="demo"></table>
<script src="/3nod_web/layui/layui.js" charset="utf-8"></script>
<script src="/3nod_web/js/jquery-1.8.3.js" charset="utf-8"></script>
<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        laydate.render({
            elem: '#time',//指定元素
            format: 'yyyy-MM',
            type: 'month'
        });
    });


    layui.use('table', function () {
        var table = layui.table;

        //方法级渲染
        table.render({
            elem: '#demo'
            , url: '/3nod_web/report/suppliedMaterialsBadTop10Report/'
            , cellMinWidth: 150
            , cols: [
                [

                    {field: 'supplierKey', title: '供应商编码', sort: true, width: 150}
                    , {field: 'supplierName', title: '供应商名称', sort: true, width: 150}
                    , {field: 'skuTypes', title: '物料大类'}
                    , {field: 'amount', title: '总批数'}
                    , {field: 'okQty', title: '合格批数'}
                    , {field: 'percentOfPass', title: '合格率'}
                    , {field: 'checkGrade', title: '进料检验评分', edit: 'text'}
                    , {field: 'percentOfPassGrade', title: '产品交付质量合格率评分', edit: 'text'}
                    , {field: 'roH5Grade', title: 'RoH5管控评分', edit: 'text'}
                    , {field: 'adaptabilityGrade', title: '配合度评分', edit: 'text'}
                    , {field: 'amountGrade', title: '总得分', edit: 'text'}
                    , {field: 'levels', title: '等级', edit: 'text'}
                ]
            ]
            , id: 'testReload'
            , page: true
            , limits: [20, 50, 100, 200, 500, 1000, 2000, 3000, 4000, 5000]
            , limit: 20
            , height: 'full-90'
        });

        var $ = layui.$, active = {
            reload: function () {
                var time = $('[name=time]');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        time: time.val(),
                    }
                }, 'data');
            }
        };

        $('#search').on('click', function () {
            active['reload'] ? active['reload'].call(this) : '';
        });
        $('#save').on('click', function () {
            active['reload'] ? active['reload'].call(this) : '';
        });
        //按回车提交
        $(".layui-input-inline").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                // $('button.search123').trigger("click");//触发搜索按钮的点击事件
                active['reload'] ? active['reload'].call(this) : '';
            }
        });
    });
    //单元格在线编辑编辑
    layui.use('table', function () {
        var table = layui.table;
        table.on('edit(demo)', function (obj) {
            var $ = layui.$;
            var value = obj.value //得到修改后的值
                , data = obj.data;//得到所在行所有键值
            console.log(data);
            console.log(value);
            //调用修改方法修改当前行
            $.ajax({
                url: "/3nod_web/report/updateTop10", // ajax请求路径
                type: 'POST',
                contentType: 'application/json; charset=UTF-8',
                async: false,
                dataType: 'json',
                data: JSON.stringify(data),
                success: function (data) {
                    // thisReload();
                }
            });

        });
    });

    //重载当前表格
    function thisReload() {
        layui.use('table', function () {
            var table = layui.table;
            var $ = layui.$, active = {
                reload: function () {
                    //执行重载
                    table.reload('testReload', {}, 'data');
                }
            };
            var type = "reload";
            active[type] ? active[type].call(this) : '';
        })
    }
</script>

</body>
</html>